package fun.coding.stack;

import java.util.Stack;

public class StackRelatedImpl implements StackRelated {

    /*
     * Using two stacks to implement a queue. 
     */
    private Stack<Integer> pushStack = new Stack<Integer>();
    private Stack<Integer> popStack = new Stack<Integer>();
    
    @Override
    public void queuePush(int a) {
        pushStack.push(a);
    }

    @Override
    public int queuePoll() {
        if(popStack.isEmpty()) {
            while(!pushStack.isEmpty()) {
                popStack.push(pushStack.pop());
            }
        }
        
        return popStack.isEmpty() ? -1 : popStack.pop();
    }

    @Override
    public int queuePeek() {
        if(popStack.isEmpty()) {
            while(!pushStack.isEmpty()) {
                popStack.push(pushStack.pop());
            }
        }
        return popStack.isEmpty() ? -1 : popStack.peek();
    }

}
